home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / Amos / AMOSList-1097 / AMOSLIST / text0048.txt < prev    next >
Encoding:
Text File  |  1998-06-24  |  1.2 KB  |  63 lines

  1. Subj:    Re: Sorting routine.
  2.  
  3.  
  4. >Hi!
  5.  
  6. >Is there a smooth way to sort 20 variables???
  7. >and not do like this..
  8.  
  9. >--------------------------------
  10. >If score1_1(1)>score2_1(1)
  11. >   Loke S7+40,Leek(S5+20)
  12. >endif
  13. >if score1_2(2)>score2_1(1)
  14. >   loke s7+60,leek(s5+40)
  15. >endif
  16. >-------------------------------
  17.  
  18. >This way makes the program very big..!
  19. >Any soloution anyone????
  20.  
  21.  
  22. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23.  
  24. There's loads of different methods of sorting an array.
  25. Most of them use loops. The quickest ones use recursion.
  26.  
  27. I'm sure there's a "Sort" command in Amos. I recall ever having
  28. used it, but I'm sure it's there.
  29.  
  30. If you can't use that, try this:
  31.  
  32. cnt   - loop counter
  33. cnt2  - second loop counter
  34. siz   - number of array elements
  35. srt() - the array to sort
  36. tmp   - a temporary var to hold a copy of one srt().
  37.  
  38. For cnt=1 to siz-1
  39.    For cnt2=cnt+1 to siz
  40.       Rem Out of sequence?
  41.       If srt(cnt) > srt(cnt2)
  42.      Rem then swap the two variables.
  43.          tmp=srt(cnt)
  44.      srt(cnt)=srt(cnt2)
  45.      srt(cnt2)=tmp
  46.       Endif
  47.    Next
  48. Next
  49.  
  50.  
  51. A recursive 'quick sort' would be much quicker, but isn't easy to
  52. understand like this one.
  53.  
  54. Hope that answers your question.
  55.  
  56. See ya.
  57.  
  58.  
  59.  
  60.  
  61.          SimonC.
  62.  
  63.